perm filename A42.TEX[106,RWF]1 blob
sn#807732 filedate 1985-09-20 generic text, type C, neo UTF8
COMMENT ā VALID 00002 PAGES
C REC PAGE DESCRIPTION
C00001 00001
C00002 00002 \magnification\magstephalf
C00008 ENDMK
Cā;
\magnification\magstephalf
\input macro.tex
\def\today{\ifcase\month\or
January\or February\or March\or April\or May\or June\or
July\or August\or September\or October\or November\or December\fi
\space\number\day, \number\year}
\baselineskip 14pt
\rm
\line{\sevenrm a42.tex[106,phy] \today\hfill}
\bigskip
Representation of data in the computer---a 7-card
poker hand could be represented by:
\smallskip
\disleft 25pt:
(1):One string:
\smallskip\halign{\qquad\qquad\lft{\tt #}\cr
S = AD QH ... 2C\cr
\qq \hbox{(Ace of diamonds, Queen of Hearts, etc.)}\cr}
\smallskip
\disleft 25pt:
(2):An array of seven strings:
\smallskip\halign{\qquad\qquad\lft{\tt #}\cr
S[1]=AD\cr
S[2]=QH\cr
\qq \hbox{etc.}\cr}
\smallskip
\disleft 25pt:
(3):Two arrays of numbers, where the rank is 11 for Jacks, 12~for Queens, etc.,
and the suits are 1~for clubs, 2~for diamonds, etc.
\smallskip\halign{\qquad\qquad\lft{\tt #}\cr
RANK[1]=14 SUIT[1]=2\cr
RANK[2]=12 SUIT[2]=3\cr}
\smallskip
\disleft 25pt:
(4):Two such arrays, but with the cards arranged in increasing order of rank.
\smallskip
\disleft 25pt:
(5):A two-dimensional array of integers, with the first subscript being the rank,
the second the suit. A~one in the array indicates the presence of the card;
a zero its absence.
\smallskip
\disleft 25pt:
(6):The same, except that an extra row and column contain the sums of the cards in
each row and column; that is, the number of cards of each suit, and the
number of each rank.
\smallskip
To find out what kind of a poker hand you have may be easy or hard, depending on
which of these representations you use. To tell if you have a flush (*****: define)
in the first representation requires going through the string counting occurrences
of {\tt C}, {\tt D}, {\tt H}, and~{\tt S};
to find the high card in the flush is even messier. To do the
same in the sixth representation, one can look at the four row sums and see if
any one is at least five; if so, the last~1 in that row is the high card of a
flush.
\medskip
{\bf Exercise:}
Test in one or more of these representations, whether the hand contains a
full house (three cards of one rank, two of another).
\medskip
A final project in a programming course was to test which of two such poker hands
was the better.
Similarly, to represent the relative strength of one flush (as best) relative to
another, one approach is to rank the cards, then pack the ranks into a number, like
\smallskip\halign{\qquad\qquad\lft{\tt #}\cr
11 08 06 03 02\qquad\hbox{(for }J 8 6 3 2\hbox{).}\cr}
\smallskip\noindent
Another is to have positions in each number, which are set to 1 if a card is
present, 0~if absent, with more significant positions for higher cards, eg:
\smallskip\halign{\qquad\qquad\lft{\tt #}\cr
14 13 12 11 10 9 8 7 6 5 4 3 2 1\cr
\phantom{0}0 \phantom{0}0 \phantom{0}0 \phantom{0}1 \phantom{0}0
0 1 0 1 0 0 1 1 0\cr}
\smallskip\noindent
Once obtaining the numbers for two hands, the larger number is from the better hand.
\bigskip
\parindent0pt
\copyright 1984 Robert W. Floyd
First draft March 28, 1984
\bye